<template>
  <div class="commentList">
    <slot></slot>

    <ul class="commentBox">
      <van-list
  v-model="loading"
  :finished="finished"
  finished-text="没有更多了"
  @load="onLoad"
>
      <li v-for="(item, index) in commentList1" :key="index" class="userComment">
        <img :src="item.user.avatarUrl" alt="" class="userImg" />
        <ul class="ulBox">
          <li class="userName">{{ item.user.nickname }}</li>
          <li
            :class="isOmit == index ? '' : ' commentContent'"
            @click="changeOmit(index)">
            {{ item.content }}
          </li>
        </ul>
      </li>
      </van-list>
    </ul>

  </div>
</template>

<script>
export default {
  name: "CommentList",
  data() {
    return {
      commentList: [],
      isOmit: true,

        list: [],
      loading: false,
      finished: false,
      commentListNewData:[]
    };
  },
  methods: {
    changeOmit(data) {
      this.isOmit = data;
    },
        onLoad() {
      // 异步更新数据
      // setTimeout 仅做示例，真实场景中一般为 ajax 请求
      setTimeout(() => {
        for (let i = 0; i < 10; i++) {
          this.list.push(this.commentList1.length + 1);
        }

        // 加载状态结束
        this.loading = false;

        // 数据全部加载完成
        if (this.list.length >= 40) {
          this.finished = true;
        }
      }, 1000);
    },
  },
  props:{
      commentList1:[Array,String],
      allComment:Array
  },
  created () {
    // this.commentListNewData=JSON.parse(this.commentList1)
  }
};
</script>
<style lang="less" scoped>
.commentList{
  width:100%;
  // padding:0 5px; 
}
.commentBox {
  display: flex;
  padding: 10px 10px;
  padding-left: 0;
  flex-flow: wrap;

  li {
    padding: 5px 10px;
    // padding-right: 0;
    // padding-left: 0;
      // width:100%;  
  }
}
.userComment {
  display: flex;
  align-items: center;
  font-size: 14px;
  border-bottom: 1px solid rgb(238, 229, 229);
  position: relative;
  li {
    padding-bottom: 0;
  }
}

.userImg {
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

.userName{
  font-size: 13px;
  color: rgb(135, 182, 189);
}

</style>